1
|
|
|
const Inquire = require('./Inquire'); |
2
|
|
|
const Generate = require('./Generate'); |
3
|
|
|
const Structure = require('./Structure'); |
4
|
|
|
|
5
|
|
|
const speak = require('./speak'); |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* ReactRaise class |
9
|
|
|
* @class ReactRaise |
10
|
|
|
*/ |
11
|
|
|
class ReactRaise { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Creates an instance of ReactRaise. |
15
|
|
|
* @memberOf ReactRaise |
16
|
|
|
*/ |
17
|
|
|
constructor() { |
18
|
|
|
this.privateProps = new WeakMap(); |
19
|
|
|
this.privateProps.set(this, { |
20
|
|
|
setupInfo: {}, |
21
|
|
|
}); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* set or alter the private properties; |
26
|
|
|
* @param {String} key - key of item to set |
27
|
|
|
* @param {any} value - value to store inside private property |
28
|
|
|
* @returns {object} set private properties |
29
|
|
|
* @memberOf ReactRaise |
30
|
|
|
*/ |
31
|
|
|
setProp(key, value) { |
32
|
|
|
return this.privateProps.set( |
33
|
|
|
this, |
34
|
|
|
Object.assign({}, this.privateProps.get(this), { [key]: value }) |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* get the private properties; |
40
|
|
|
* @param {String} key - key of item to get |
41
|
|
|
* @returns {object} set private properties |
42
|
|
|
* @memberOf ReactRaise |
43
|
|
|
*/ |
44
|
|
|
getProp(key) { |
45
|
|
|
return this.privateProps.get(this)[key]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* initialize command and ask setup questions |
50
|
|
|
* @param {String} name - name of react app to create |
51
|
|
|
* @param {Function} callback - function to execute after answers |
52
|
|
|
* @param {String} basepath - base path to create the files in |
53
|
|
|
* has been given |
54
|
|
|
* @returns {Void} returns nothing |
55
|
|
|
* @memberOf ReactRaise |
56
|
|
|
*/ |
57
|
|
|
init(name, callback, basepath) { |
58
|
|
|
const configGenerate = new Generate(basepath); |
59
|
|
|
const fileStructure = new Structure(basepath); |
60
|
|
|
const startInquire = new Inquire(); |
61
|
|
|
startInquire.question( |
62
|
|
|
'description', |
63
|
|
|
'input', |
64
|
|
|
'Can you describe your app[optional]'); |
65
|
|
|
startInquire.question( |
66
|
|
|
'main', |
67
|
|
|
'input', |
68
|
|
|
'What is the main entry file of your app[Default: index.js]'); |
69
|
|
|
startInquire.question( |
70
|
|
|
'author', |
71
|
|
|
'input', |
72
|
|
|
'What is your name[optional]'); |
73
|
|
|
startInquire.question( |
74
|
|
|
'license', |
75
|
|
|
'input', |
76
|
|
|
'What is license is your app under[Default: MIT]' |
77
|
|
|
); |
78
|
|
|
startInquire.question( |
79
|
|
|
'express', |
80
|
|
|
'input', |
81
|
|
|
'Do you want to configure an express server with this app(y/n)', |
82
|
|
|
'yesNo' |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
startInquire.ask((answers) => { |
86
|
|
|
this.setProp('setupInfo', answers); |
87
|
|
|
if (callback) { |
88
|
|
|
callback(); |
89
|
|
|
} |
90
|
|
|
fileStructure.build(name); |
91
|
|
|
configGenerate.all(Object.assign({}, answers, { name })); |
92
|
|
|
|
93
|
|
|
speak(`> Your Project ${name}, has been setup`); |
94
|
|
|
speak('> run: \'npm install\''); |
95
|
|
|
speak('> start development server with: \'npm run start-dev\''); |
96
|
|
|
}); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
module.exports = ReactRaise; |
101
|
|
|
|